<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .square {
      width: 100px;
      height: 100px;
      border-radius: 0px 100px 100px 0px;
      background-color: tomato;
    }

    .round-box {
      position: relative;
    }

    .round {
      width: 100px;
      height: 100px;
      border-radius: 50%;
      position: absolute;
      top: 0;
      left: 0px;
      background-color: red;
      border: 1px solid black;
      opacity: 0.5;
    }
  </style>
</head>

<body>
  <div style="display: flex;">
    <div class="square"></div>
    <div class="round-box">
      <div class="round"></div>
    </div>
  </div>
</body>
<script>
  const roundBox = document.getElementsByClassName('round-box')[0]
  let isHidden = false
  setInterval(() => {
    if (isHidden) return
    cereat();
  }, 3000)
  function cereat() {
    const newRound = document.createElement('div')
    newRound.className = 'round'
    roundBox.appendChild(newRound)
  }
  // let load = 0
  setInterval(() => {
    if (isHidden) return
    for (let i = 0; i < roundBox.children.length; i++) {
      const element = roundBox.children[i];
      const left = element.style.left;
      if (!left) element.style.left = '0px';
      else {
        element.style.left = (+left.replace('px', '') + 1) + 'px';
      }
    }
    // load++
    // if (load % 150 === 0) cereat()
  }, 20)
  window.addEventListener('visibilitychange', () => {
    if (document.hidden) {
      console.log('页面不可见')
      isHidden = true
    } else {
      console.log('页面可见')
      isHidden = false
    }
  })
  // visibilitychange
</script>

</html>